import Vue from 'vue'
import Vuex from 'vuex'
import router from '@/router'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    collapse: false,
    routerTitle: '首页',
    tabList: [],
    activeName: '/home',
    clienHeight: document.documentElement.clientHeight > 700 ? document.documentElement.clientHeight : 700,
  },
  getters: {
    menuWidth(state) {
      return state.collapse ? "64px" : "250px"
    },
    title(state) {
      return state.collapse ? "医疗" : "我的医疗管理平台"
    }
  },
  mutations: {
    changclienHeight(s) {
      s.clienHeight = document.documentElement.clientHeight > 700 ? document.documentElement.clientHeight : 700
    },
    changeCollapse(state, bool) {
      state.collapse = bool;
    },
    changeRouterTitle(state, title) {
      state.routerTitle = title
    },
    addtabList(state, tab) {
      // console.log('asdvasdvasdvasdvadvadv');
      state.activeName = tab.path
      let obj = state.tabList.find(item => item.path === tab.path)
      if (obj) return
      state.tabList.push(tab)
    },
    removeTabList(state, arr) {
      if (state.tabList.length === 1 && state.activeName === '/home') {
        return
      }
      state.tabList = state.tabList.filter(item => !arr.includes(item.path))
      let route = state.tabList[state.tabList.length - 1]
      if (arr.includes(state.activeName)) {
        router.push(route ? route.path : '/home')
      }
    },
    changeActiveName(state, name) {
      state.activeName = name
    }
  },
  actions: {},
  modules: {},
})
